// toast modal的封装
// 1. toast的封装
// const toast = (options = {}) => {}
// 从options中解构出来需要的属性
export const toast = ({ title = '数据加载中~', icon = 'none', duration = 2000, mask = true } = {}) => {
  wx.showToast({
    title,
    icon,
    duration,
    mask
  })
}

// 封装modal
export const modal = (options = {}) => {
  return new Promise((resolve) => {
    // 设置默认参数
    const defaultOptions = {
      title: '提示',
      content: '您确定执行该操作吗?',
      confirmColor: '#f3514f'
    }
    // 合并参数
    const opts = Object.assign({}, defaultOptions, options)

    wx.showModal({
      ...opts,
      complete: ({ confirm, cancel }) => {
        // 都通过返回resolve 判断点击确认还是取消 再根据 true/false 执行后续操作
        // 确认
       confirm && resolve(true)

       // 取消
       confirm && resolve(false)
      }
    })
  })
}